package com.jiyun.demo;

import com.mongodb.BasicDBObject;
import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.bson.Document;

public class Delete {
    public static void main(String[] args) {
        //创建链接
        MongoClient client = new MongoClient("127.0.0.1");
        //获取数据库
        MongoDatabase database = client.getDatabase("2108a");
        //获取集合
        MongoCollection<Document> user = database.getCollection("user");
        BasicDBObject id = new BasicDBObject("_id", "2");
        user.deleteOne(id);
        client.close();
    }
}
